package com.zyh.demo;

public class ExceptionDemo5 {
    static int num = 17;

    public static void main(String[] args) throws Exception {
        try (MyRuntimeException2 m2 = new MyRuntimeException2()) {
            try {
                if (num < 18) {
                    throw new MyRuntimeException2("我的运行时期异常对象暴露了");
                }
            } catch (MyRuntimeException2 e) {
                System.out.println("异常解决了");
            }
        }
    }

    static class MyRuntimeException2 extends RuntimeException implements AutoCloseable {
        public MyRuntimeException2() {
        }

        public MyRuntimeException2(String message) {
            super(message);
        }

        @Override
        public void close() throws Exception {
            ExceptionDemo5.num = 20;
            System.out.println("ExceptionDemo5.num = " + ExceptionDemo5.num);
            System.out.println("资源关闭");
        }
    }
}